/****

    activequant - activestocks.eu

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

	
	contact  : contact@activestocks.eu
    homepage : http://www.activestocks.eu

 ****/
package org.activequant.core.types;

/**
 * Simple tuple data container. <br>
 * A Holder for 2 objects of type A and B(any 2 types - each must implement the Comparable interface though). Holds the following associated variables:
 * <ul>
 * <li>object1(A)</li>
 * <li>object2(B)</li>
 * </ul>
 * <br>
 * <b>History:</b><br>
 * - [24.06.2007] Created (Ulrich Staudinger)<br>
 * - [16.01.2008] Added compareTo, equals (Erik Nijkamp)<br>
 * 
 * @author Ulrich Staudinger
 */
public class Tuple<A extends Comparable<A>, B extends Comparable<B>> implements Comparable<Tuple<A, B>> {
	/**
	 * private A object1 = null;
	 */
	private A object1 = null;
	/**
	 * private B object2 = null;
	 */
	private B object2 = null;
	/**
	 * empty Tuple constructor
	 */
	public Tuple() {

	}
	/**
	 * constructs a Tuple using the given o1(A) and o2(B) to set its associated object1(A) and object2(B)
	 * @param o1
	 * @param o2
	 */
	public Tuple(A o1, B o2) {
		this.object1 = o1;
		this.object2 = o2;
	}
	/**
	 * returns the associated object1(A)
	 * @return
	 */
	public A getObject1() {
		return object1;
	}
	/**
	 * sets the associated object1(A) with the given object1(A)
	 * @param object1
	 */
	public void setObject1(A object1) {
		this.object1 = object1;
	}
	/**
	 * returns the associated object2(B)
	 * @return
	 */
	public B getObject2() {
		return object2;
	}
	/**
	 * sets the associated object2(B) with the given object2(B)
	 * @param object2
	 */
	public void setObject2(B object2) {
		this.object2 = object2;
	}

	public int compareTo(Tuple<A, B> other) {
		if (this == other)
			return 0;
		if (null == other)
			throw new NullPointerException();
		if (0 != object1.compareTo(other.object1)) {
			return object1.compareTo(other.object1);
		}
		return object2.compareTo(other.object2);
	}

	public boolean equals(Tuple<A, B> other) {
		if (this == other)
			return true;
		if (null == other)
			return false;
		return (object1.equals(other.object1) && object2.equals(other.object2));
	}
	
	public String toString() {
		return (object1==null?"":object1.toString())+"/"+(object2==null?"":object2.toString());
	}
}